package com.sujie;

import ch.qos.logback.core.encoder.ByteArrayUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.util.AsciiString;
import io.netty.util.ByteProcessor;
import lombok.extern.java.Log;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
import java.util.Arrays;

/**
 * @author: xinmi
 * @date: 2020/11/26
 * @description:
 */
@Log
public class ByteBufTest {

    private static final int RIGHT = (2 << 15) - 1;

    public static void main(String[] argc){

        byte[] bresult = ByteArrayUtil.hexStringToByteArray("7e00200101000c0203010301000001ff0603020201000001ff03030104033e7f");

        ByteBuf buf = Unpooled.wrappedBuffer(bresult);

        buf.skipBytes(7);

        ByteBuf headBuf = buf.readBytes(12);
        log.info(ByteBufUtil.hexDump(headBuf));

        byte test = (byte) 0xc0;
        log.info(String.valueOf(test));

        log.info(String.valueOf(Byte.toUnsignedInt(test)));

        short crc = -12874;

        int crc32 = crc & RIGHT;

        log.info("crc32 = " + crc32 );








/*        log.info(ByteBufUtil.hexDump(buf));

        byte[] length = ByteArrayUtil.hexStringToByteArray("0020");

        ByteBuf buflength = Unpooled.wrappedBuffer(length);
        //log.info(String.valueOf(buflength.readInt()));
        log.info(String.valueOf(buflength.readShort()));
        //log.info(String.valueOf(buflength.readByte()));*/




    }

}
